import { Component, OnInit,Input, Output, EventEmitter, AfterViewInit, ViewChild ,ViewChildren} from '@angular/core';
import { ConmonService } from "../../service/common.service";
// import { HeadTitleComponent } from '../head-title/head-title.component';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
  private domainVal: string = "afcat.com.cn";
  private token:any;
  private SumMyApplyWorkInfo:string = '';
  private SumBacklogListInfo:string = "";
  private SumProjectWorkListInfo:string = "";
  private IsProjectManager:string = "";
  public doSomething():void{
    alert("收到了子组件的自定义事件！");
  }
  constructor(private service: ConmonService) {
    this.token = this.service.token;
    console.log(this.token)
    // console.log(must);
    let _this = this;
    // // this.service.withoutBodyData('DailyWorkBasicInfo',this.token);
    // // this.IsProjectManager = 'N';
    // clearInterval(lookTimer);
    var num = 1;
    var lookTimer = setTimeout(function(){
      console.log(_this.service.openId);
      if (_this.service.openId !== undefined) {
        _this.service.getToken(1, _this.service.openId, 'DailyWorkBasicInfo', true);
        // _this.service.withoutBodyData('DailyWorkBasicInfo');
        clearTimeout(lookTimer);
        console.log('成功发送请求');
        return;
      } else {
        num++;
        console.log("循环次数"+num);
      }
    },500);
  }
  getToken(openId) {
    // this.service.getToken(1, openId, 'DailyWorkBasicInfo', true);
  }
  ngAfterViewInit(){
  }
  ngOnInit() {
    // let openId = window.localStorage.getItem("openId");
    // console.log(openId);
    // this.getToken(openId);
    // this.service.getToken(1, 'openId', 'DailyWorkBasicInfo', true);
    // this.service.getToken(1, this.service.openId, 'DailyWorkBasicInfo', true);
    let _this = this;
    clearTimeout(timer);
    var timer = setTimeout(function() {
      _this.SumMyApplyWorkInfo = _this.service.SumMyApplyWorkInfo;
      _this.SumBacklogListInfo = _this.service.SumBacklogListInfo;
      _this.SumProjectWorkListInfo = _this.service.SumProjectWorkListInfo;
      _this.IsProjectManager = _this.service.IsProjectManager;
    },500);
    console.log('屏幕分辨率的宽:' + window.screen.width);
    console.log('屏幕可用工作区宽度:' + window.screen.availWidth);
    console.log('网页可见区域宽:' + document.body.clientWidth);
    console.log('网页可见区域宽(包括线):' + document.body.offsetWidth);
    console.log('网页正文全文宽:' + document.body.scrollWidth);

    // let d = new Date();
    // // d.setTime(d.getTime() + (1 * 24 * 60 * 60 * 1000));
    // d.setTime(d.getTime() + (5 * 1000));
    // let expires = "expires=" + d.toUTCString();
    // document.cookie = "ATOKEN=" + this.token + ";domain=" + this.domainVal + ";path=/;" + expires + ";";
    // let _this = this;
    // $.ajax({
    //   async: false, // 同步请求 false，异步请求 true
    //   type: "POST", // 请求类型，POST、GET
    //   xhrFields: {
    //     withCredentials: true
    //   },
    //   crossDomain: true,
    //   url: _this.url, // 请求的地址
    //   data: { crmData: "{'head': {'ServName':'DailyWorkBasicInfo','SeqNo':'123123123123123123123123','employId':'000123'}}"},
    //   dataType: 'json',
    //   success: function (responseData) {
    //     console.log(responseData);
    //   },
    //   error: function (XMLHttpRequest, textStatus, errorThrown) {
    //     // 处理请求发生异常
    //     console.log("请求发生异常！" + textStatus + errorThrown);
    //   },
    // });
  }

}
